//
//  WCNMeetingHomePage.m
//  WCN
//
//  Created by wsj2015 on 16/5/25.
//  Copyright © 2016年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNMeetingHomePage.h"
#import <YTXAnimations/UIView+YTXAnimateCSS.h>
#import "WCNJoinMeetingVC.h"
#import "WCNCreateMeetingVC.h"
//#import "WCNNavigationController.h"
#import <ZhumuSDK/ZhumuSDK.h>
#import "WCImageView +setImage.h"
#import "UIKit+AFNetworking.h"

#import "JCAlertView.h"

@interface WCNMeetingHomePage ()
@property (weak, nonatomic) IBOutlet UIButton *creatMeetingBtn;
@property (weak, nonatomic) IBOutlet UIButton *joinMeetingBtn;
@property (weak, nonatomic) IBOutlet UILabel *joinLabel;
@property (weak, nonatomic) IBOutlet UILabel *creatLabel;

@property (weak, nonatomic) IBOutlet UILabel *alertLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *intersapce;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *createBtnWidht;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *creatBtnHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *joinBtnHeightC;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *joinBtnWidth;
@property (copy, nonatomic)  NSDictionary *zhumuDict;


@end

@implementation WCNMeetingHomePage

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
     [[ZhumuSDK sharedSDK] setZhumuRootController:self.navigationController];
    self.title = @"在线会议";
    [self configUI];
    [self.creatMeetingBtn ytx_fadeInLeftAnimtionWithDurationTime:.5f];
    [self.joinMeetingBtn ytx_fadeInRightAnimtionWithDurationTime:.5f];
    
    [self getInfo];
}

- (void)getInfo {

    defineWeakSelf;
//    MBProgressHUD *hud = [[WCPopupLayerManager shareMg] showSimple:[UIApplication sharedApplication].keyWindow];
    Account *account =[[WCDefaultManager shareMg] account];
    
    NSString *mobile = account.mobile;
    NSString *url = [kgetZhuMuUserInfo stringByAppendingFormat:@"/%@",mobile];
//    NSDictionary *param = @{@"userName":mobile};
    [[WCNetworkAccessManager sharedMg] POST:url parameters:nil success:^(NSDictionary *result){
        weakSelf.creatMeetingBtn.enabled = YES;
//        weakSelf.joinMeetingBtn.enabled = YES;
//        [weakSelf.joinMeetingBtn setBackgroundImage:[UIImage imageNamed:@"meeting_creat"] forState:UIControlStateNormal];
        [weakSelf.creatMeetingBtn setBackgroundImage:[UIImage imageNamed:@"meeting_join"] forState:UIControlStateNormal];
        weakSelf.joinLabel.textColor = [UIColor blackColor];
        weakSelf.creatLabel.textColor = [UIColor blackColor];
        _zhumuDict = result[@"data"];
        weakSelf.alertLabel.text = @"";
        
    } failure:^(NSString *msg) {
        if ([msg isEqualToString:@"未找到改用户..."]) {
            
            weakSelf.alertLabel.text = @"您还没有开通创建会议权限，如需开通请联系客服电话：400-100-9630";
            weakSelf.creatMeetingBtn.enabled = NO;
//            weakSelf.joinMeetingBtn.enabled = NO;
//            [weakSelf.joinMeetingBtn setBackgroundImage:[UIImage imageNamed:@"meeting_creat_gray"] forState:UIControlStateNormal];
            [weakSelf.creatMeetingBtn setBackgroundImage:[UIImage imageNamed:@"meeting_join_gray"] forState:UIControlStateNormal];
            weakSelf.joinLabel.textColor = [UIColor grayColor];
        }
        weakSelf.creatLabel.textColor = [UIColor grayColor];
        
    }netError:nil always:^{
//        [hud hide:YES];
    }];

}


- (void)configUI{
    
    if (kScreenWidth == 320 && kScreenHeight ==480) {//iphone4
        
    }else if(kScreenWidth == 320 && kScreenHeight ==568){ //iphone 5
        self.topSpace.constant =70;
        self.intersapce.constant = 60;
        
    }else if(kScreenWidth == 375 && kScreenHeight == 667){ //iphone 6
        self.topSpace.constant =70;
        self.intersapce.constant = 60;
        self.creatBtnHeight.constant  =160;
        self.createBtnWidht.constant  =160;
        self.joinBtnWidth.constant  =160;
        self.joinBtnHeightC.constant  =160;
        
    }else if(kScreenWidth == 414 && kScreenHeight == 736){ //iphone 6P
        self.topSpace.constant =80;
        self.intersapce.constant = 80;
        self.creatBtnHeight.constant  =160;
        self.createBtnWidht.constant  =160;
        self.joinBtnWidth.constant  =160;
        self.joinBtnHeightC.constant  =160;
        
    }
}

//提示当前网络是否wifi
- (void)alertMessage:(NSString *)message vc:(UIViewController *)vc{
    
    [JCAlertView showTwoButtonsWithTitle:nil Message:message ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"确定" Click:^{
       [self.navigationController pushViewController:vc animated:YES];
    } ButtonType:JCAlertViewButtonTypeCancel ButtonTitle:@"取消" Click:nil];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}

- (IBAction)joinAction:(id)sender {
    WCNJoinMeetingVC *vc = [WCNJoinMeetingVC new];
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (IBAction)createAction:(id)sender {
    WCNCreateMeetingVC *vc = [WCNCreateMeetingVC new];
    vc.email = _zhumuDict[@"email"];
    [self.navigationController pushViewController:vc animated:YES];
    
}


@end
